package com.yangkz.code.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @ProjectName: mybatis-gencode
 * @Package: com.yangkz.code.utils
 * @ClassName: IdGeneratorUtil
 * @Author: yangkunzhen
 * @Description: TODO
 * @Date: 2019/6/18 0018 下午 4:02
 * @Version: 1.0
 */
public class IdGeneratorUtil {

    public static String genSimpleNo() {
        IdGenerator idGenerator = new DefaultIdGenerator();
        return idGenerator.next();
    }

    public static String genConfigNo(String prefix, String splitString, int initNum) {
        IdGeneratorConfig config = new DefaultIdGeneratorConfig() {
            @Override
            public String getSplitString() {
                if (StringUtils.isBlank(splitString)) {
                    return "";
                }
                return splitString;
            }
            @Override
            public int getInitial() {
                return initNum;
            }
            @Override
            public String getPrefix() {
                if (StringUtils.isBlank(prefix)) {
                    return "";
                }
                return prefix;
            }
        };
        IdGenerator idGenerator = new DefaultIdGenerator(config);
        return idGenerator.next();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String id = genConfigNo("TC",null,1);
            System.out.println(id);
        }

    }
}
